<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>美年旅游</title>
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../css/orderset.css">
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
</head>
<body class="hold-transition">
<div id="app">

    <el-container>
        <el-aside width="210">
            <el-col :span="24">
                <el-menu
                        default-active="1"
                        class="el-menu-vertical-demo"
                        @open="handleOpen"
                        @close="handleClose">
                    <el-submenu index="1">
                        <template slot="title">
                            <i class="el-icon-location"></i>
                            <span>未完善功能</span>
                        </template>
                            <template slot="title">未完善功能</template>
                            <el-menu-item index="1-1">未完善功能</el-menu-item>
                            <el-menu-item index="1-2">未完善功能</el-menu-item>
                        </el-submenu>
                    </el-submenu>
                </el-menu>
            </el-col>
        </el-aside>
        <el-container>

            <el-header>

            </el-header>

            <el-main>
                <template>
                    <el-table
                            :data="tableData"
                            style="width: 100%">
                        <el-table-column
                                label="序号"
                                width="180">
                            <template slot-scope="scope">
                                <i class="el-icon-time"></i>
                                <span style="margin-left: 10px">{{ scope.$index+1}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="部门名称"
                                width="180">
                            <template slot-scope="scope">
                                <i class="el-icon-time"></i>
                                <span style="margin-left: 10px">{{ scope.row.deptName }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="部门级别"
                                width="180">
                            <template slot-scope="scope">
                                <i class="el-icon-time"></i>
                                <span style="margin-left: 10px">{{ scope.row.deptLoc }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                <el-button
                                        size="mini"
                                        @click="handleAdd()">增加
                                </el-button>
                                <el-button
                                        size="mini"
                                        @click="handleUpdate(scope.$index, scope.row)">编辑
                                </el-button>
                                <el-button
                                        size="mini"
                                        type="danger"
                                        @click="handleDelete(scope.$index, scope.row)">删除
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </template>
            </el-main>

        </el-container>
    </el-container>

    <div class="add-form">
        <el-dialog title="新增跟团游" :visible.sync="dialogFormVisible">
            <template>
                <el-tabs v-model="activeName" type="card">
                    <el-tab-pane label="基本信息" name="first">
                        <el-form label-position="right" label-width="100px">
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="部门名称">
                                        <el-input v-model="formData.deptName"/>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="部门级别">
                                        <el-input v-model="formData.deptLoc"/>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form>
                    </el-tab-pane>
                </el-tabs>
            </template>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取消</el-button>
                <el-button type="primary" @click="handleAddO()">确定</el-button>
            </div>
        </el-dialog>
    </div>

    <div class="add-form">
        <el-dialog title="新增跟团游" :visible.sync="dialogFormVisibleEdit">
            <template>
                <el-tabs v-model="activeName" type="card">
                    <el-tab-pane label="基本信息" name="first">
                        <el-form label-position="right" label-width="100px">
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="部门名称">
                                        <el-input v-model="formData.deptName"/>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="部门级别">
                                        <el-input v-model="formData.deptLoc"/>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form>
                    </el-tab-pane>
                </el-tabs>
            </template>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisibleEdit = false">取消</el-button>
                <el-button type="primary" @click="update(formData.deptId)">确定</el-button>
            </div>
        </el-dialog>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            activeName: 'first',//添加/编辑窗口Tab标签名称
            tableData: [],
            formData: {},//表单数据
            activeIndex: '1',
            activeIndex2: '1',
            dialogFormVisible: false,
            dialogFormVisibleEdit: false
        },
        created: function () {//在vue初始化时调用
            this.findAll();
        },
        methods: {
            handleAdd() {
                this.formData = {};
                this.dialogFormVisible = true;
            },
            handleAddO() {
                // 发送ajax
                axios.post("/add", this.formData).then(response => {
                    this.$message.success("插入成功");
                    this.dialogFormVisible = false;
                    this.findAll();
                }).catch(error => {
                    this.$message.error("查询失败");
                });
            },
            update(deptId){
                // 发送ajax
                axios.post("/handleUpdate", this.formData).then(response => {
                    this.$message.success("更新成功");
                    this.dialogFormVisibleEdit = false;
                    this.findAll();
                }).catch(error => {
                    this.$message.error("查询失败");
                });
            },
            handleUpdate(index, row) {
                var deptId = row.deptId;
                this.dialogFormVisibleEdit = true;

                axios.get("/findByDeptId?deptId="+deptId).then(response => {
                    this.formData = response.data.data;
                }).catch(error => {
                    this.$message.error("查询失败");
                });
            },
            findAll() {
                axios.get("/getAllDepts").then(response => {
                    this.tableData = response.data.depts;
                }).catch(error => {
                    this.$message.error("查询失败");
                });
            },
            handleOpen(key, keyPath) {
            },
            handleClose(key, keyPath) {
            },
            handleSelect(key, keyPath) {
            },
            handleDelete(index, row) {
                var deptId = row.deptId;

                this.$confirm('此操作将永久删除该学生, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get("/delete?deptId=" + deptId).then(response => {
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        this.findAll();

                    }).catch(error => {
                        this.$message({
                            type: 'error',
                            message: '删除出现问题'
                        });
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            }
        }
    })
</script>


<style>
    .el-header, .el-footer {
        background-color: #B3C0D1;
        color: #333;
        text-align: center;
        line-height: 60px;
    }

    .el-aside {
        background-color: #D3DCE6;
        color: #333;
        text-align: center;
        line-height: 200px;
    }

    .el-main {
        background-color: #E9EEF3;
        color: #333;
        text-align: center;
        line-height: 160px;
    }

    body > .el-container {
        margin-bottom: 40px;
    }

    .el-container:nth-child(5) .el-aside,
    .el-container:nth-child(6) .el-aside {
        line-height: 260px;
    }

    .el-container:nth-child(7) .el-aside {
        line-height: 320px;
    }
</style>
</html>